require('../css/users.less')
common.footer('users')
window.onload =function(){
let userId = localStorage.getItem('userId');

//dom获取
 let img = document.querySelector('.tupian img');
 let name = document.querySelector('.name');
 let liuyan = document.querySelector('.liuyan');
 let fenzhong = document.querySelector('#fenzhong');
 let qianka = document.querySelector('#qianka');
 let touxiangs = document.querySelector('#touxiangs');
$http.get('/users/accountinfo',{userId},function(res){
    if(res.data.nickname){
        name.innerText =res.data.nickname
    }
    if(res.data.sign){
        liuyan.innerText =res.data.sign
    }
    if(res.data.imgurl){
        img.src =res.data.imgurl
    }
})

$http.get('/users/mysportsBadge',{userId},function(res){
    let sports = res.data.sports;
    fenzhong.textContent = sports.times;
    qianka.textContent = sports.calorie
 })

 touxiangs.addEventListener('change',function(){

    let file = this.files[0];

    $http.uploadFile('/users/upload','imgurl',file,function(res){
        let imgurl = res.data; 
        let data = {
            imgurl:imgurl, 
            userId:userId
        }
        $http.post('/users/userEdit',data,function(res){
            if(res.status ==0){
                common.toast(1,'修改头像成功');
                userInfo()
            }else{
                common.toast(0,res.msg);
            }
        })
    })
})
}